\doxysection{my\+\_\+tree.\+h}
\hypertarget{my__tree_8h_source}{}\label{my__tree_8h_source}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include<iostream>}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include<utility>}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include<vector>}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include<list>}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include<stack>}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include<queue>}}
\DoxyCodeLine{00007\ \textcolor{preprocessor}{\#include<algorithm>}}
\DoxyCodeLine{00008\ \textcolor{preprocessor}{\#include<string>}}
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include<functional>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#include<cassert>}}
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include<cstdlib>}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include<cmath>}}
\DoxyCodeLine{00013\ }
\DoxyCodeLine{00014\ \textcolor{preprocessor}{\#define\ MAX\_LEN\ 100;}}
\DoxyCodeLine{00015\ }
\DoxyCodeLine{00016\ \textcolor{keyword}{using\ namespace\ }std;}
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00018\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00019\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{struct_tree_node}{TreeNode}};}
\DoxyCodeLine{00020\ }
\DoxyCodeLine{00021\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00022\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classmy__tree}{my\_tree}};}
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00024\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00025\ ostream\&\ \mbox{\hyperlink{classmy__tree_aa1da950e13ff2a3c6fcaca11015a4e20}{operator<<}}(ostream\&\ os,\mbox{\hyperlink{classmy__tree}{my\_tree<T>}}\ Tree);}
\DoxyCodeLine{00026\ }
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00028\ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/定义工具函数-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00029\ \textcolor{keywordtype}{void}\ print(\textcolor{keywordtype}{int}\ x)\{}
\DoxyCodeLine{00030\ \ \ \ \ cout<<x<<\textcolor{charliteral}{'\ '};}
\DoxyCodeLine{00031\ \}}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ }
\DoxyCodeLine{00034\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00035\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a9aa06543930fa8ddb21c1ebabbff3ecf}{print\_node}}(\mbox{\hyperlink{classmy__tree_a9c79fe45a5aae4cbb2efbc5bb050a135}{my\_tree<T>}}\ Tree,\textcolor{keywordtype}{int}\ x)\{}
\DoxyCodeLine{00036\ \ \ \ \ \textcolor{keywordflow}{if}(x<Tree.v.size())\{}
\DoxyCodeLine{00037\ \ \ \ \ \ \ \ \ cout<<Tree.v[x];}
\DoxyCodeLine{00038\ \ \ \ \ \}\ }
\DoxyCodeLine{00039\ \}}
\DoxyCodeLine{00040\ }
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00042\ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/定义主类-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00049\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00050\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{struct_tree_node_a04c315e7d9af382fa471a9d3858e8c72}{TreeNode}}\ \{}
\DoxyCodeLine{00051\ \ \ \ \ T\ data;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 节点数据}}
\DoxyCodeLine{00052\ \ \ \ \ \textcolor{keywordtype}{int}\ parent;\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 双亲索引（-\/1表示无双亲，即根节点）}}
\DoxyCodeLine{00053\ \ \ \ \ \textcolor{keywordtype}{int}\ first\_child;\ \ \ \ \ \ \ \textcolor{comment}{//\ 第一个孩子的索引（-\/1表示无孩子）}}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keywordtype}{int}\ next\_sibling;\ \ \ \ \ \ \textcolor{comment}{//\ 下一个兄弟节点的索引（-\/1表示无下一个兄弟）}}
\DoxyCodeLine{00055\ }
\DoxyCodeLine{00064\ \ \ \ \ \mbox{\hyperlink{struct_tree_node_a04c315e7d9af382fa471a9d3858e8c72}{TreeNode}}(T\ d\ =\ T(),\ \textcolor{keywordtype}{int}\ p\ =\ -\/1,\ \textcolor{keywordtype}{int}\ fc\ =\ -\/1,\ \textcolor{keywordtype}{int}\ ns\ =\ -\/1)}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ :\ data(d),\ parent(p),\ first\_child(fc),\ next\_sibling(ns)\ \{\}}
\DoxyCodeLine{00066\ \ \ \ \ }
\DoxyCodeLine{00067\ \};}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ }
\DoxyCodeLine{00076\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00077\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classmy__tree_a9c79fe45a5aae4cbb2efbc5bb050a135}{my\_tree}}\{}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keyword}{private}:}
\DoxyCodeLine{00079\ \ \ \ \ \ \ \ \ vector<TreeNode<T>>\ v;}
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/构造操作-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00087\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a9c79fe45a5aae4cbb2efbc5bb050a135}{my\_tree}}(T\ val=0)\{}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{struct_tree_node}{TreeNode<T>}}\ p(val);}
\DoxyCodeLine{00089\ \ \ \ \ \ \ \ \ \ \ \ \ v.push\_back(p);}
\DoxyCodeLine{00090\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/查询操作-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_ab1c9be9f0c6b3fee4b3322841014b8a3}{get\_root}}();\ \ \ \ \ }
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(vector<int>\&\ children,\textcolor{keywordtype}{int}\ root);\ \ \ \ \ }
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(queue<int>\&\ children,\textcolor{keywordtype}{int}\ root);\ \ \ \ \ }
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a6d1fb6a1cb4a9064cb2538d1fbaa8b06}{get\_height}}(\textcolor{keywordtype}{int}\ index);\ \ \ \ \ }
\DoxyCodeLine{00120\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a6d1fb6a1cb4a9064cb2538d1fbaa8b06}{get\_height}}();\ \ \ \ \ }
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a2cef5c6b97d67ca6a49b0577600f5254}{get\_h\_layer\_nodes}}(\textcolor{keywordtype}{int}\ h);\ \ \ \ \ }
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a3b2c0f604e05f25ffd37a6d0f45a2a26}{get\_last\_layer\_nodes}}();}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a826f12f2e9f55f7436fa8d3e1d41da93}{get\_nodes\_nums}}();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ T\ \mbox{\hyperlink{classmy__tree_afbfe59f624cf7f8a7f8ebb3cc9ad4514}{get\_value}}();\ \ \ \ \ \ \ }
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a00b270f7f42b067702dadafc78f04bf6}{show\_k\_node}}(\textcolor{keywordtype}{int}\ k);}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/增删操作-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a0d6043fc3e177a775f837fc9dfaea31a}{insert}}(\mbox{\hyperlink{struct_tree_node}{TreeNode<T>}}\ node);}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/遍历操作-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a49e765fa53962f4ce7d11d6cdb8a12ad}{show\_binary\_tree\_with\_root}}(\textcolor{keywordtype}{string}\ mode,\textcolor{keywordtype}{int}\ root);}
\DoxyCodeLine{00168\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a0020d5a85f5d99734466c6ef5d255b72}{show\_binary\_tree}}(\textcolor{keywordtype}{string}\ mode);\ \ \ \ \ }
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ Function>}
\DoxyCodeLine{00176\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_aadec19d1d256df1f27412e80bd6579d1}{traversal\_binary\_tree\_with\_root}}(\textcolor{keywordtype}{string}\ mode,\textcolor{keywordtype}{int}\ root,Function\ F);}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ Function>}
\DoxyCodeLine{00183\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a99d1637e88625af9f06b6d020730f634}{traversal\_binary\_tree}}(\textcolor{keywordtype}{string}\ mode,Function\ F);\ \ \ \ \ \ \ \ }
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00185\ \ \ \ \ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/操作符重载-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00192\ \ \ \ \ \ \ \ \ \textcolor{keyword}{friend}\ ostream\&\ operator<<<>(ostream\&\ os,\mbox{\hyperlink{classmy__tree}{my\_tree<T>}}\ Tree);}
\DoxyCodeLine{00198\ \ \ \ \ \ \ \ \ T\ \mbox{\hyperlink{classmy__tree_a908b1d95027e3afb39e7e33b59de10b9}{operator[]}}(\textcolor{keywordtype}{int}\ index)\{}
\DoxyCodeLine{00199\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(index<v.size())\{}
\DoxyCodeLine{00200\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ v[index].data;\ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00202\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\{}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ v[0].data;}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a9aa06543930fa8ddb21c1ebabbff3ecf}{print\_node<>}}(\mbox{\hyperlink{classmy__tree}{my\_tree<T>}}\ Tree,\textcolor{keywordtype}{int}\ x);}
\DoxyCodeLine{00213\ \};}
\DoxyCodeLine{00214\ }
\DoxyCodeLine{00215\ }
\DoxyCodeLine{00216\ }
\DoxyCodeLine{00217\ }
\DoxyCodeLine{00218\ }
\DoxyCodeLine{00219\ }
\DoxyCodeLine{00220\ }
\DoxyCodeLine{00221\ }
\DoxyCodeLine{00222\ }
\DoxyCodeLine{00223\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00224\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_ab1c9be9f0c6b3fee4b3322841014b8a3}{my\_tree<T>::get\_root}}()\ \{}
\DoxyCodeLine{00225\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i=0;i<v.size();i++)\{}
\DoxyCodeLine{00226\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[i].parent==-\/1)\{}
\DoxyCodeLine{00227\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ i;}
\DoxyCodeLine{00228\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00229\ \ \ \ \ \}}
\DoxyCodeLine{00230\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00231\ \}}
\DoxyCodeLine{00232\ }
\DoxyCodeLine{00233\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00234\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{my\_tree<T>::get\_children}}(vector<int>\&\ children,\textcolor{keywordtype}{int}\ root)\ \{}
\DoxyCodeLine{00235\ \ \ \ \ \textcolor{keywordtype}{int}\ index=root;}
\DoxyCodeLine{00236\ \ \ \ \ \textcolor{keywordflow}{if}(v[index].first\_child!=-\/1)\{}
\DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ index=v[index].first\_child;\ \ \ \ \ }
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ children.push\_back(index);}
\DoxyCodeLine{00239\ \ \ \ \ \}}
\DoxyCodeLine{00240\ \ \ \ \ \textcolor{keywordflow}{if}(v[index].next\_sibling!=-\/1)\{}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}(v[index].next\_sibling!=-\/1)\{}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \ \ \ \ index=v[index].next\_sibling;}
\DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ \ \ \ \ children.push\_back(index);}
\DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ \}\ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00245\ \ \ \ \ \}}
\DoxyCodeLine{00246\ \ \ \ \ return\ ;}
\DoxyCodeLine{00247\ \}}
\DoxyCodeLine{00248\ }
\DoxyCodeLine{00249\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00250\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{my\_tree<T>::get\_children}}(queue<int>\&\ children,\textcolor{keywordtype}{int}\ root)\ \{}
\DoxyCodeLine{00251\ \ \ \ \ \textcolor{keywordtype}{int}\ index=root;}
\DoxyCodeLine{00252\ \ \ \ \ \textcolor{keywordflow}{if}(v[index].first\_child!=-\/1)\{}
\DoxyCodeLine{00253\ \ \ \ \ \ \ \ \ index=v[index].first\_child;\ \ \ \ \ }
\DoxyCodeLine{00254\ \ \ \ \ \ \ \ \ children.push(index);}
\DoxyCodeLine{00255\ \ \ \ \ \}}
\DoxyCodeLine{00256\ \ \ \ \ \textcolor{keywordflow}{if}(v[index].next\_sibling!=-\/1)\{}
\DoxyCodeLine{00257\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}(v[index].next\_sibling!=-\/1)\{}
\DoxyCodeLine{00258\ \ \ \ \ \ \ \ \ \ \ \ \ index=v[index].next\_sibling;}
\DoxyCodeLine{00259\ \ \ \ \ \ \ \ \ \ \ \ \ children.push(index);}
\DoxyCodeLine{00260\ \ \ \ \ \ \ \ \ \}\ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00261\ \ \ \ \ \}}
\DoxyCodeLine{00262\ \ \ \ \ return\ ;}
\DoxyCodeLine{00263\ \}}
\DoxyCodeLine{00264\ }
\DoxyCodeLine{00265\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00266\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a6d1fb6a1cb4a9064cb2538d1fbaa8b06}{my\_tree<T>::get\_height}}(\textcolor{keywordtype}{int}\ index)\{}
\DoxyCodeLine{00267\ \ \ \ \ \textcolor{keywordtype}{int}\ height=0;}
\DoxyCodeLine{00268\ \ \ \ \ \textcolor{keywordflow}{if}(v[index].first\_child==-\/1)\{}
\DoxyCodeLine{00269\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1+height;}
\DoxyCodeLine{00270\ \ \ \ \ \}}
\DoxyCodeLine{00271\ \ \ \ \ vector<int>\ children;}
\DoxyCodeLine{00272\ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,index);}
\DoxyCodeLine{00273\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ it:children)\{}
\DoxyCodeLine{00274\ \ \ \ \ \ \ \ \ height=max(height,\mbox{\hyperlink{classmy__tree_a532dfbc3d3835014944957a61b7a8bce}{get\_height}}(it));}
\DoxyCodeLine{00275\ \ \ \ \ \}}
\DoxyCodeLine{00276\ \ \ \ \ \textcolor{keywordflow}{return}\ 1+height;}
\DoxyCodeLine{00277\ \}}
\DoxyCodeLine{00278\ }
\DoxyCodeLine{00279\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00280\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a6d1fb6a1cb4a9064cb2538d1fbaa8b06}{my\_tree<T>::get\_height}}()\{}
\DoxyCodeLine{00281\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classmy__tree_a532dfbc3d3835014944957a61b7a8bce}{get\_height}}(0);}
\DoxyCodeLine{00282\ \}}
\DoxyCodeLine{00283\ }
\DoxyCodeLine{00284\ }
\DoxyCodeLine{00285\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00286\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a2cef5c6b97d67ca6a49b0577600f5254}{my\_tree<T>::get\_h\_layer\_nodes}}(\textcolor{keywordtype}{int}\ h)\{}
\DoxyCodeLine{00287\ \ \ \ \ \textcolor{keywordflow}{if}(h>\mbox{\hyperlink{classmy__tree_a532dfbc3d3835014944957a61b7a8bce}{get\_height}}())\{}
\DoxyCodeLine{00288\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00289\ \ \ \ \ \}}
\DoxyCodeLine{00290\ \ \ \ \ \textcolor{keywordflow}{if}(h==1)\{}
\DoxyCodeLine{00291\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{00292\ \ \ \ \ \}}
\DoxyCodeLine{00293\ \ \ \ \ \textcolor{keywordflow}{else}\{}
\DoxyCodeLine{00294\ \ \ \ \ \ \ \ \ vector<int>\ layer1;}
\DoxyCodeLine{00295\ \ \ \ \ \ \ \ \ vector<int>\ layer2;}
\DoxyCodeLine{00296\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ level=1;}
\DoxyCodeLine{00297\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(layer1,0);}
\DoxyCodeLine{00298\ \ \ \ \ \ \ \ \ level++;\ }
\DoxyCodeLine{00299\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}(1)\{}
\DoxyCodeLine{00300\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//level代表当前所在层}}
\DoxyCodeLine{00301\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//也就是正要放节点的那一层}}
\DoxyCodeLine{00302\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//实际上，奇数层放在了layer2，偶数层放在了layer1\ \ }}
\DoxyCodeLine{00303\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ level已经是2了，如果h是2，这时候就应该返回layer1中的\ }}
\DoxyCodeLine{00304\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(level\%2==0)\{}
\DoxyCodeLine{00305\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ layer2.clear();}
\DoxyCodeLine{00306\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ it:layer1)\{}
\DoxyCodeLine{00307\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ vector<int>\ children;}
\DoxyCodeLine{00308\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,it);}
\DoxyCodeLine{00309\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ layer2.insert(layer2.end(),\ children.begin(),\ children.end());}
\DoxyCodeLine{00310\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00311\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(level==h)\{}
\DoxyCodeLine{00312\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ layer1.size();}
\DoxyCodeLine{00313\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00314\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ level++;}
\DoxyCodeLine{00315\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00316\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\{}
\DoxyCodeLine{00317\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ layer1.clear();}
\DoxyCodeLine{00318\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ it:layer2)\{}
\DoxyCodeLine{00319\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ vector<int>\ children;}
\DoxyCodeLine{00320\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,it);}
\DoxyCodeLine{00321\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ layer1.insert(layer1.end(),\ children.begin(),\ children.end());}
\DoxyCodeLine{00322\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00323\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(level==h)\{}
\DoxyCodeLine{00324\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ layer2.size();}
\DoxyCodeLine{00325\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00326\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ level++;}
\DoxyCodeLine{00327\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00328\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00329\ \ \ \ \ \}}
\DoxyCodeLine{00330\ \}}
\DoxyCodeLine{00331\ }
\DoxyCodeLine{00332\ }
\DoxyCodeLine{00333\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00334\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a3b2c0f604e05f25ffd37a6d0f45a2a26}{my\_tree<T>::get\_last\_layer\_nodes}}()\{}
\DoxyCodeLine{00335\ \ \ \ \ \textcolor{keywordtype}{int}\ height=\mbox{\hyperlink{classmy__tree_a532dfbc3d3835014944957a61b7a8bce}{get\_height}}();}
\DoxyCodeLine{00336\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classmy__tree_a2cef5c6b97d67ca6a49b0577600f5254}{get\_h\_layer\_nodes}}(height);}
\DoxyCodeLine{00337\ \}}
\DoxyCodeLine{00338\ }
\DoxyCodeLine{00339\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00340\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{classmy__tree_a826f12f2e9f55f7436fa8d3e1d41da93}{my\_tree<T>::get\_nodes\_nums}}()\{}
\DoxyCodeLine{00341\ \ \ \ \ \textcolor{keywordflow}{return}\ this-\/>v.size();}
\DoxyCodeLine{00342\ \}}
\DoxyCodeLine{00343\ }
\DoxyCodeLine{00344\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00345\ T\ \mbox{\hyperlink{classmy__tree_afbfe59f624cf7f8a7f8ebb3cc9ad4514}{my\_tree<T>::get\_value}}()\{}
\DoxyCodeLine{00346\ \ \ \ \ assert((v.size()!=0)\&\&(\textcolor{stringliteral}{"{}illegal:Tree\ has\ no\ root!"{}}));}
\DoxyCodeLine{00347\ \ \ \ \ cout<<v[0].data<<endl;}
\DoxyCodeLine{00348\ \ \ \ \ \textcolor{keywordflow}{return}\ v[0].data;}
\DoxyCodeLine{00349\ \}}
\DoxyCodeLine{00350\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00351\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00352\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a00b270f7f42b067702dadafc78f04bf6}{my\_tree<T>::show\_k\_node}}(\textcolor{keywordtype}{int}\ k)\ \{}
\DoxyCodeLine{00353\ \ \ \ \ cout<<v[k];}
\DoxyCodeLine{00354\ \}}
\DoxyCodeLine{00355\ }
\DoxyCodeLine{00356\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00357\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a0d6043fc3e177a775f837fc9dfaea31a}{my\_tree<T>::insert}}(\mbox{\hyperlink{struct_tree_node}{TreeNode<T>}}\ node)\{}
\DoxyCodeLine{00358\ \ \ \ \ \textcolor{keywordflow}{if}(node.parent<v.size())\{}
\DoxyCodeLine{00359\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ index=node.parent;}
\DoxyCodeLine{00360\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}((v[node.parent].first\_child==-\/1))\{}
\DoxyCodeLine{00361\ \ \ \ \ \ \ \ \ \ \ \ \ v[node.parent].first\_child=v.size();}
\DoxyCodeLine{00362\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00363\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\{}
\DoxyCodeLine{00364\ \ \ \ \ \ \ \ \ \ \ \ \ index=v[index].first\_child;\ }
\DoxyCodeLine{00365\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}(1)\{}
\DoxyCodeLine{00366\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[index].next\_sibling==-\/1)\{}
\DoxyCodeLine{00367\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ v[index].next\_sibling=v.size();\ }
\DoxyCodeLine{00368\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00369\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00370\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ index=v[index].next\_sibling;}
\DoxyCodeLine{00371\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00372\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00373\ \ \ \ \ \}}
\DoxyCodeLine{00374\ \ \ \ \ v.push\_back(node);\ }
\DoxyCodeLine{00375\ \}\ }
\DoxyCodeLine{00376\ }
\DoxyCodeLine{00377\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00378\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a49e765fa53962f4ce7d11d6cdb8a12ad}{my\_tree<T>::show\_binary\_tree\_with\_root}}(\textcolor{keywordtype}{string}\ mode,\textcolor{keywordtype}{int}\ root)\ \{}
\DoxyCodeLine{00379\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}first\_root"{}})\{}
\DoxyCodeLine{00380\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a00b270f7f42b067702dadafc78f04bf6}{show\_k\_node}}(root);\ }
\DoxyCodeLine{00381\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[root].first\_child==-\/1)\{}
\DoxyCodeLine{00382\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00383\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00384\ \ \ \ \ \ \ \ \ vector<int>\ children;}
\DoxyCodeLine{00385\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,root);}
\DoxyCodeLine{00386\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ it:children)\{}
\DoxyCodeLine{00387\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a49e765fa53962f4ce7d11d6cdb8a12ad}{show\_binary\_tree\_with\_root}}(mode,it);\ \ \ \ \ \ }
\DoxyCodeLine{00388\ \ \ \ \ \ \ \ \ \}\ \ \ \ \ \ \ }
\DoxyCodeLine{00389\ \ \ \ \ \}\ }
\DoxyCodeLine{00390\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}last\_root"{}})\{}
\DoxyCodeLine{00391\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[root].first\_child==-\/1)\{}
\DoxyCodeLine{00392\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a00b270f7f42b067702dadafc78f04bf6}{show\_k\_node}}(root);\ }
\DoxyCodeLine{00393\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00394\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00395\ \ \ \ \ \ \ \ \ vector<int>\ children;}
\DoxyCodeLine{00396\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,root);}
\DoxyCodeLine{00397\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ it:children)\{}
\DoxyCodeLine{00398\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a49e765fa53962f4ce7d11d6cdb8a12ad}{show\_binary\_tree\_with\_root}}(mode,it);\ \ \ \ \ \ }
\DoxyCodeLine{00399\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00400\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a00b270f7f42b067702dadafc78f04bf6}{show\_k\_node}}(root);\ }
\DoxyCodeLine{00401\ \ \ \ \ \}\ }
\DoxyCodeLine{00402\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}layer\_first"{}})\{}
\DoxyCodeLine{00403\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ index=root;}
\DoxyCodeLine{00404\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a00b270f7f42b067702dadafc78f04bf6}{show\_k\_node}}(root);\ }
\DoxyCodeLine{00405\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[root].first\_child==-\/1)\{}
\DoxyCodeLine{00406\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00407\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00408\ \ \ \ \ \ \ \ \ queue<int>\ children;}
\DoxyCodeLine{00409\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,root);}
\DoxyCodeLine{00410\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00411\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}(1)\{}
\DoxyCodeLine{00412\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(children.size()==0)\{}
\DoxyCodeLine{00413\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00414\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[children.front()].first\_child!=-\/1)\{}
\DoxyCodeLine{00416\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,children.front());}
\DoxyCodeLine{00417\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00418\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a00b270f7f42b067702dadafc78f04bf6}{show\_k\_node}}(children.front());\ }
\DoxyCodeLine{00419\ \ \ \ \ \ \ \ \ \ \ \ \ children.pop();}
\DoxyCodeLine{00420\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00421\ \ \ \ \ \ \ \ \ return\ ;}
\DoxyCodeLine{00422\ \ \ \ \ \}\ }
\DoxyCodeLine{00423\ \}}
\DoxyCodeLine{00424\ }
\DoxyCodeLine{00425\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00426\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a0020d5a85f5d99734466c6ef5d255b72}{my\_tree<T>::show\_binary\_tree}}(\textcolor{keywordtype}{string}\ mode)\ \{}
\DoxyCodeLine{00427\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}first\_root"{}})\{}
\DoxyCodeLine{00428\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ root=\mbox{\hyperlink{classmy__tree_ab1c9be9f0c6b3fee4b3322841014b8a3}{get\_root}}();}
\DoxyCodeLine{00429\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a49e765fa53962f4ce7d11d6cdb8a12ad}{show\_binary\_tree\_with\_root}}(mode,root);}
\DoxyCodeLine{00430\ \ \ \ \ \ \ \ \ return\ ;}
\DoxyCodeLine{00431\ \ \ \ \ \}\ }
\DoxyCodeLine{00432\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}last\_root"{}})\{}
\DoxyCodeLine{00433\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ root=\mbox{\hyperlink{classmy__tree_ab1c9be9f0c6b3fee4b3322841014b8a3}{get\_root}}();}
\DoxyCodeLine{00434\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a49e765fa53962f4ce7d11d6cdb8a12ad}{show\_binary\_tree\_with\_root}}(mode,root);\ \ \ \ \ \ \ \ }
\DoxyCodeLine{00435\ \ \ \ \ \ \ \ \ return\ ;}
\DoxyCodeLine{00436\ \ \ \ \ \}\ }
\DoxyCodeLine{00437\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}layer\_first"{}})\{}
\DoxyCodeLine{00438\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ root=\mbox{\hyperlink{classmy__tree_ab1c9be9f0c6b3fee4b3322841014b8a3}{get\_root}}();}
\DoxyCodeLine{00439\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a49e765fa53962f4ce7d11d6cdb8a12ad}{show\_binary\_tree\_with\_root}}(mode,root);}
\DoxyCodeLine{00440\ \ \ \ \ \ \ \ \ return\ ;}
\DoxyCodeLine{00441\ \ \ \ \ \}\ }
\DoxyCodeLine{00442\ \}}
\DoxyCodeLine{00443\ }
\DoxyCodeLine{00444\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00445\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ Function>}
\DoxyCodeLine{00446\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_aadec19d1d256df1f27412e80bd6579d1}{my\_tree<T>::traversal\_binary\_tree\_with\_root}}(\textcolor{keywordtype}{string}\ mode,\textcolor{keywordtype}{int}\ root,Function\ F)\{\ \ \ }
\DoxyCodeLine{00447\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}first\_root"{}})\{}
\DoxyCodeLine{00448\ \ \ \ \ \ \ \ \ F(root);\ }
\DoxyCodeLine{00449\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[root].first\_child==-\/1)\{}
\DoxyCodeLine{00450\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00451\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00452\ \ \ \ \ \ \ \ \ vector<int>\ children;}
\DoxyCodeLine{00453\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,root);}
\DoxyCodeLine{00454\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ it:children)\{}
\DoxyCodeLine{00455\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_aadec19d1d256df1f27412e80bd6579d1}{traversal\_binary\_tree\_with\_root}}(mode,it,F);\ \ \ \ \ \ }
\DoxyCodeLine{00456\ \ \ \ \ \ \ \ \ \}\ \ \ \ \ \ \ }
\DoxyCodeLine{00457\ \ \ \ \ \}\ }
\DoxyCodeLine{00458\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}last\_root"{}})\{}
\DoxyCodeLine{00459\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[root].first\_child==-\/1)\{}
\DoxyCodeLine{00460\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_a00b270f7f42b067702dadafc78f04bf6}{show\_k\_node}}(root);\ }
\DoxyCodeLine{00461\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00462\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00463\ \ \ \ \ \ \ \ \ vector<int>\ children;}
\DoxyCodeLine{00464\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,root);}
\DoxyCodeLine{00465\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keyword}{auto}\ it:children)\{}
\DoxyCodeLine{00466\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_aadec19d1d256df1f27412e80bd6579d1}{traversal\_binary\_tree\_with\_root}}(mode,it,F);\ \ \ \ \ \ }
\DoxyCodeLine{00467\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00468\ \ \ \ \ \ \ \ \ F(root);\ }
\DoxyCodeLine{00469\ \ \ \ \ \}\ }
\DoxyCodeLine{00470\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}layer\_first"{}})\{}
\DoxyCodeLine{00471\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ index=root;}
\DoxyCodeLine{00472\ \ \ \ \ \ \ \ \ F(root);\ }
\DoxyCodeLine{00473\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[root].first\_child==-\/1)\{}
\DoxyCodeLine{00474\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00475\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00476\ \ \ \ \ \ \ \ \ queue<int>\ children;}
\DoxyCodeLine{00477\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,root);}
\DoxyCodeLine{00478\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00479\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}(1)\{}
\DoxyCodeLine{00480\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(children.size()==0)\{}
\DoxyCodeLine{00481\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00482\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00483\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(v[children.front()].first\_child!=-\/1)\{}
\DoxyCodeLine{00484\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_af25baab5cde301d7087d8c5f63727a8f}{get\_children}}(children,children.front());}
\DoxyCodeLine{00485\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00486\ \ \ \ \ \ \ \ \ \ \ \ \ F(children.front());\ }
\DoxyCodeLine{00487\ \ \ \ \ \ \ \ \ \ \ \ \ children.pop();}
\DoxyCodeLine{00488\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00489\ \ \ \ \ \ \ \ \ return\ ;}
\DoxyCodeLine{00490\ \ \ \ \ \}\ }
\DoxyCodeLine{00491\ \}}
\DoxyCodeLine{00492\ }
\DoxyCodeLine{00493\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00494\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ Function>}
\DoxyCodeLine{00495\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classmy__tree_a99d1637e88625af9f06b6d020730f634}{my\_tree<T>::traversal\_binary\_tree}}(\textcolor{keywordtype}{string}\ mode,Function\ F)\{}
\DoxyCodeLine{00496\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}first\_root"{}})\{}
\DoxyCodeLine{00497\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ root=\mbox{\hyperlink{classmy__tree_ab1c9be9f0c6b3fee4b3322841014b8a3}{get\_root}}();}
\DoxyCodeLine{00498\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_aadec19d1d256df1f27412e80bd6579d1}{traversal\_binary\_tree\_with\_root}}(mode,root,F);}
\DoxyCodeLine{00499\ \ \ \ \ \ \ \ \ return\ ;}
\DoxyCodeLine{00500\ \ \ \ \ \}\ }
\DoxyCodeLine{00501\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}last\_root"{}})\{}
\DoxyCodeLine{00502\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ root=\mbox{\hyperlink{classmy__tree_ab1c9be9f0c6b3fee4b3322841014b8a3}{get\_root}}();}
\DoxyCodeLine{00503\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_aadec19d1d256df1f27412e80bd6579d1}{traversal\_binary\_tree\_with\_root}}(mode,root,F);\ \ \ \ \ \ \ \ }
\DoxyCodeLine{00504\ \ \ \ \ \ \ \ \ return\ ;}
\DoxyCodeLine{00505\ \ \ \ \ \}\ }
\DoxyCodeLine{00506\ \ \ \ \ \textcolor{keywordflow}{if}(mode==\textcolor{stringliteral}{"{}layer\_first"{}})\{}
\DoxyCodeLine{00507\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ root=\mbox{\hyperlink{classmy__tree_ab1c9be9f0c6b3fee4b3322841014b8a3}{get\_root}}();}
\DoxyCodeLine{00508\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classmy__tree_aadec19d1d256df1f27412e80bd6579d1}{traversal\_binary\_tree\_with\_root}}(mode,root,F);}
\DoxyCodeLine{00509\ \ \ \ \ \ \ \ \ return\ ;}
\DoxyCodeLine{00510\ \ \ \ \ \}\ }
\DoxyCodeLine{00511\ \}}
\DoxyCodeLine{00512\ }
\DoxyCodeLine{00513\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00514\ ostream\&\ operator<<(ostream\&\ os,\mbox{\hyperlink{struct_tree_node}{TreeNode<T>}}\ Node)\{}
\DoxyCodeLine{00515\ \ \ \ \ os<<Node.data<<\textcolor{charliteral}{'\ '}<<Node.parent<<\textcolor{charliteral}{'\ '}<<Node.first\_child<<\textcolor{charliteral}{'\ '}<<Node.next\_sibling<<endl;}
\DoxyCodeLine{00516\ \ \ \ \ \textcolor{keywordflow}{return}\ os;}
\DoxyCodeLine{00517\ \}}
\DoxyCodeLine{00518\ }
\DoxyCodeLine{00519\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00520\ ostream\&\ \mbox{\hyperlink{classmy__tree_aa1da950e13ff2a3c6fcaca11015a4e20}{operator<<}}(ostream\&\ os,\mbox{\hyperlink{classmy__tree_a9c79fe45a5aae4cbb2efbc5bb050a135}{my\_tree<T>}}\ Tree)\{}
\DoxyCodeLine{00521\ \ \ \ \ \textcolor{keywordtype}{int}\ nodes=Tree.\mbox{\hyperlink{classmy__tree_a826f12f2e9f55f7436fa8d3e1d41da93}{get\_nodes\_nums}}();}
\DoxyCodeLine{00522\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i=0;i<nodes;i++)\{}
\DoxyCodeLine{00523\ \ \ \ \ \ \ \ \ os<<Tree.v[i];\ \ }
\DoxyCodeLine{00524\ \ \ \ \ \}}
\DoxyCodeLine{00525\ \ \ \ \ \textcolor{keywordflow}{return}\ os;}
\DoxyCodeLine{00526\ \}}
\DoxyCodeLine{00527\ }

\end{DoxyCode}
